package com.bidepan.validation.four;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.Objects;

public class CannotBlankValidation implements ConstraintValidator<CannotBlank,String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if(value!=null && value.contains(" ")){
            //获取默认提示信息
            String defaultConstraintMessage = context.getDefaultConstraintMessageTemplate();
//            System.out.println("default message: "+defaultConstraintMessage);
            //禁用默认提示信息
            context.disableDefaultConstraintViolation();
            //添加自定义提示信息
            context.buildConstraintViolationWithTemplate("can not contains blank").addConstraintViolation();
            return false;
        }
        return true;
    }
}
